<?php

namespace app\admin\model\cms;

use think\Model;
use traits\model\SoftDelete;

class AlbumModel extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'album';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    //自动写入时间戳的格式
    protected $dateFormat = 'Y-m-d H:i:s';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'table_name_text',
        'category_name'
    ];


    public function getCategoryNameAttr($value, $data)
    {
        $data['table_name'] = $data['table_name'] ?? null;
        if ($data['table_name'] == 'video_category'){
            return VideoCategoryModel::where('id',$data['category_id'])->value('platename');
        }else{
            return $value;
        }
    }
    
    public function getTableNameList()
    {
        return ['video_category' => __('Video_category')];
    }


    public function getTableNameTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['table_name']) ? $data['table_name'] : '');
        $list = $this->getTableNameList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
